%%%-------------------------------------------------------------------
%%% @author Zheng
%%% @copyright (C) 2024, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 21. 3月 2024 21:25
%%%-------------------------------------------------------------------
-module(process).
-author("Zheng").

%% API
-export([go/0,loop/0]).

go() ->
  Server = spawn(process, loop, []),
  Server ! {self(), "Hello, Server!"},
  receive
    {Pid,Msg} ->
      io:format("[Go] from: ~p received: ~p~n", [Pid,Msg]),
      Server ! {self(), stop}
  end.

loop() ->
  receive
    {From, Msg} ->
      case Msg of
        stop -> true;
        _ ->
          io:format("[Loop] from: ~p, received: ~p~n", [From,Msg]),
          From ! {self(), Msg},
          loop()
      end
  end.
